const loginBtn = document.querySelector('#btn-login');

loginBtn.addEventListener('click', async function (e) {
    const username = document.querySelector('#input-email').value.trim();
    const password = document.querySelector('#input-password').value.trim();

    if (!username || !password) {
        document.querySelector('#myToast .toast-body').innerHTML = "用户名密码不能为空"
        myToast.show()
    }

    const res = await axios({
        url: '/login',
        method: 'post',
        data: {
            username,
            password
        }
    })
    // console.log(res.data.message);

    if (res.data.message === "登录成功") {
        localStorage.setItem('token', res.data.data.token)
        setTimeout(() => {
            location.href = "./index.html"
        }, 1500);
    } else if (password.length < 6) {
        document.querySelector('#myToast .toast-body').innerHTML = `${res.data.message}`
        myToast.show()
        return
    }


})